package com.tour.service.impl;

import com.tour.bean.ReturnT;
import com.tour.bean.UserScenic;
import com.tour.dao.UserScenicMapper;
import com.tour.service.UserScenicService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName UserScenicServiceImpl
 * @Author 张梦兴
 * @Date 2020/3/15 20:20
 * @describe
 */
@Service
public class UserScenicServiceImpl implements UserScenicService {

    @Resource
    private UserScenicMapper userScenicMapper;


    @Override
    public ReturnT<String> insert(UserScenic userScenic) {

        // valid
        if (userScenic == null) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, "必要参数缺失");
        }

        userScenicMapper.insert(userScenic);
        return ReturnT.SUCCESS;
    }


    @Override
    public ReturnT<String> delete(int id) {
        int ret = userScenicMapper.delete(id);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public ReturnT<String> update(UserScenic userScenic) {
        int ret = userScenicMapper.update(userScenic);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public UserScenic load(int id) {
        return userScenicMapper.load(id);
    }

    @Override
    public UserScenic getByid(int userid, int cid) {
        return userScenicMapper.loadByidAndid(userid, cid);
    }


    @Override
    public Map<String,Object> pageList(int offset, int pagesize) {

        List<UserScenic> pageList = userScenicMapper.pageList(offset, pagesize);
        int totalCount = userScenicMapper.pageListCount(offset, pagesize);

        // result
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);

        return result;
    }

    @Override
    public List<Map<String, Object>> getUserScenicByUserId(int userid) {
        return userScenicMapper.getUserScenicByUserId(userid);
    }
}
